package com.example.demo.aop.dubbo;

import java.util.ServiceLoader;

/**
 * @author 许路路
 */
public class SpiTest {

    public static void main(String[] args) {
        hello("xululu");
    }

    public static void hello(String name) {
        HelloService helloService;
        ServiceLoader<HelloService> loader = ServiceLoader.load(HelloService.class);
        for (HelloService service : loader) {
            System.out.println(service.sayHello(name));
        }
        if (loader.iterator().hasNext()) {
            helloService = loader.iterator().next();
        } else {
            throw new IllegalStateException("Cannot find hello services.");
        }
        System.out.println("Use Hello Service: " + helloService.getClass().getName());
    }
}
